﻿
using Kinlo.SWDLib.SWD;
using System;
using System.Runtime.InteropServices;
using System.ServiceModel;

namespace Kinlo.SWDLib
{
    public static class Lib
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="passwd"></param>
        /// <param name="machineno"></param>
        /// <returns></returns>
        public static string CheckUserDo(string name, string passwd, string machineno)
        {
            var client = new MESInterfaceSoapClient();
            return client.CheckUserDo(name, passwd, machineno); 
        }
        /// <summary>
        /// 设备状态
        /// </summary>
        /// <param name="deviceCode">设备编号</param>
        /// <param name="deviceStatus">设备状态 （1、Down-设备停机，2、Wait – 设备待机，3、Warn – 设备报警，4、Run-正常运行）--备注：单词必须写对，不区分大小写</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <param name="deviceErrorInfo">设备异常的详细信息 设备异常的详细信息数据格式为|错误代码1：详细错误原因1|错误代码2：详细错误原因2|  （按照此格式可以一次性上传多个设备异常原因）</param>
        /// <param name="userCode">员工编号</param>
        /// <returns></returns>
        public static string DeviecStatusInfo(string deviceCode, string deviceStatus, string startTime,string endTime,string deviceErrorInfo,string userCode)
        {
            var client = new MESInterfaceSoapClient();
            return client.DeviecStatusInfo(deviceCode, deviceStatus, startTime, endTime, deviceErrorInfo, userCode); 
        }

        /// <summary>
        /// 工序校验功能
        /// </summary>
        /// <param name="M_SN">产品条码</param>
        /// <param name="M_MACHINCENO">设备编号</param>
        /// <param name="M_EMP">用户名</param>
        /// <returns></returns>
        public static string GroupTest(string M_SN,string M_MACHINCENO,string M_EMP, string MoNumber, string GroupName)
        {
            var client = new MESInterfaceSoapClient();
            return client.GroupTest(M_SN, M_MACHINCENO, M_EMP, MoNumber, GroupName); 
        }

        /// <summary>
        /// 工序校验功能
        /// </summary>
        /// <param name="M_SN">产品条码</param>
        /// <param name="M_MACHINCENO">设备编号</param>
        /// <param name="M_EMP">用户名</param>
        /// <returns></returns>
        public static string ItemsGroupCheck(string MO, string M_MACHINCENO, string Item, string ItemLot)
        {
            var client = new MESInterfaceSoapClient();
            return client.ItemsGroupCheck(MO, M_MACHINCENO, Item, ItemLot);
             
        }

        /// <summary>
        ///  称重数据上传MES
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static string TestDataGroupInfo( string s  ){
            try
            {
                var client = new MESInterfaceSoapClient();
                return client.TestDataGroupInfo(s);
                 
            }
            catch(EndpointNotFoundException enex)
            {
                return $"NotConnect {enex}";

            }catch(Exception ex)
            {
                return ex.Message;
            }
        }
        /// <summary>
        /// 获一注前后重量
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static string GetWeightBeforeInjectionA(string s)
        {
            var client = new MESInterfaceSoapClient();
            return client.GetWeightBeforeInjectionA(s); 
        }

        public static string GetWeightBeforeInjectionB(string s)
        {
            var client = new MESInterfaceSoapClient();
            return client.GetWeightBeforeInjectionB(s);
        }
        public static string GetWeightBeforeInjectionC(string s)
        {
            var client = new MESInterfaceSoapClient();
            return client.GetWeightBeforeInjectionC(s);
        }
    }
}
